$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'dataview/viewuserpostslist/list',
        datatype: "json",
		postData:requestParameters,
        colModel: [			
			{ label: 'id', name: 'id', index: 'id', width: 50, key: true },
			{ label: '昵称', name: 'nickname', index: 'username', width: 80 },
			{ label: '类型', name: 'type', index: 'type', width: 80 },
			{ label: '点赞数', name: 'likeCount', index: 'like_count', width: 80 },
			{ label: '评论数', name: 'commentCount', index: 'comment_count', width: 80 },
			{ label: '分享数', name: 'shareCount', index: 'share_count', width: 80 },
			{ label: '标签', name: 'tags', index: 'tags', width: 80 },
			{ label: '位置', name: 'location', index: 'location', width: 80 },
			{ label: '位置信息', name: 'locationName', index: 'location_name', width: 80 },
			{ label: '权限', name: 'viewPolicy', index: 'view_policy', width: 80 },
			{ label: '发布时间', name: 'adddate', index: 'adddate', width: 80 ,formatter:timestampForMS},
			{ label: '最后编辑时间', name: 'lastEdit', index: 'last_edit', width: 80 ,formatter:timestampForMS},
			{ label: '操作', name: '_operation', index: '_operation',align: "center", sortable: false, editable: false, width: 80 ,formatter:function (cellvalue, options, row) {
				var buttons = [];
				buttons.push('<div class="grid-operation-button">')
				buttons.push(str_format('<a class="label label-info" target="_blank" href="postsinfo.html?uid={0}">查看详情</a>',row.id));
				buttons.push('</div>');
				return buttons.join("&nbsp;")
			}}
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order",
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#webpage',
	data:{
		showList: true,
		title: null,
		viewuserpostslist: {},
	},
	methods: {
		query: function () {
			vm.reload();
		},

		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "dataview/viewuserpostslist/delete",
                    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(userId){
			$.get(baseURL + "user/user/info/"+userId, function(r){
                vm.user = r.user;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		}
	}
});
